package com.ruoyi.interfaced.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.interfaced.domain.ShopOrderInfoInter;
import com.ruoyi.interfaced.service.IShopOrderInfoInterService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 订单Controller
 * 
 * @author ruoyi
 * @date 2021-12-03
 */
@RestController
@RequestMapping("/interfaced/info")
public class ShopOrderInfoInterController extends BaseController
{
    @Autowired
    private IShopOrderInfoInterService shopOrderInfoService;

    /**
     * 添加订单
     */
    @GetMapping("/insert")
    public String insert(ShopOrderInfoInter shopOrderInfo){
        System.out.println(shopOrderInfo);
        int a=shopOrderInfoService.insert(shopOrderInfo);
        System.out.println(shopOrderInfo);
        return "1";
    }

    /**
     * 查询订单列表
     */
//    @PreAuthorize("@ss.hasPermi('order:info:list')")
    @GetMapping("/list")
    public TableDataInfo list(ShopOrderInfoInter shopOrderInfo)
    {
        System.out.println(shopOrderInfo);
        startPage();
        List<ShopOrderInfoInter> list = shopOrderInfoService.selectShopOrderInfoList(shopOrderInfo);
        return getDataTable(list);
    }

    /**
     * 导出订单列表
     */
    @PreAuthorize("@ss.hasPermi('order:info:export')")
    @Log(title = "订单", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, ShopOrderInfoInter shopOrderInfo)
    {
        List<ShopOrderInfoInter> list = shopOrderInfoService.selectShopOrderInfoList(shopOrderInfo);
        ExcelUtil<ShopOrderInfoInter> util = new ExcelUtil<ShopOrderInfoInter>(ShopOrderInfoInter.class);
        util.exportExcel(response, list, "订单数据");
    }

    /**
     * 获取订单详细信息
     */
    @PreAuthorize("@ss.hasPermi('order:info:query')")
    @GetMapping(value = "/{orderNo}")
    public AjaxResult getInfo(@PathVariable("orderNo") String orderNo)
    {
        return AjaxResult.success(shopOrderInfoService.selectShopOrderInfoByOrderNo(orderNo));
    }

    /**
     * 新增订单
     */
    @PreAuthorize("@ss.hasPermi('order:info:add')")
    @Log(title = "订单", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody ShopOrderInfoInter shopOrderInfo)
    {
        return toAjax(shopOrderInfoService.insertShopOrderInfo(shopOrderInfo));
    }

    /**
     * 修改订单
     */
    @PreAuthorize("@ss.hasPermi('order:info:edit')")
    @Log(title = "订单", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody ShopOrderInfoInter shopOrderInfo)
    {
        return toAjax(shopOrderInfoService.updateShopOrderInfo(shopOrderInfo));
    }

    /**
     * 删除订单
     */
    @PreAuthorize("@ss.hasPermi('order:info:remove')")
    @Log(title = "订单", businessType = BusinessType.DELETE)
	@DeleteMapping("/{orderNos}")
    public AjaxResult remove(@PathVariable String[] orderNos)
    {
        return toAjax(shopOrderInfoService.deleteShopOrderInfoByOrderNos(orderNos));
    }
}
